import pandas as pd
from pyecharts import options as opts
from pyecharts.charts options TreeMap
from pyecharts.globals import ThemeType
df = pd.read_excel('某店铺促销方式分析.xlsx')
total = df['购买人数'].sum()
tree = []
for i in range(len(df.index)):
    dic = {}
    dic['name'] = df['促销方式'][i]
    dic['value'] = round(int(df['购买人数'][i]) / total * 100, 2)
    dic['children'] = [
        {
            'name': df['促销方式'][i] + '-男'
            'value': round(int(df['男'][i]) / total * 100, 2)
        },
    {
        'name': df['促销方式'][i] + '-女'
        'value': round(int(df['女'][i]) / total * 100, 2)
    }
    ]